import router from "@/router";
import moment from "moment";

export const getTime = () => {
    const time = new Date();
    const hours = time.getHours();
    if (hours < 9) return "早上";
    else if (hours < 12) return "上午"
    else if (hours < 18) return "下午"
    else return "晚上"
}
// 将时间戳转为年月日格式
export const toDate = (timeStamp:number)=>moment(timeStamp).format("YYYY-MM-DD HH:mm:ss")
// 获取服务器图片地址
export const getImage = (imgUrl:string)=>import.meta.env.VITE_APP_BASE_API+"/"+imgUrl;
// 获取到token
export const GET_TOKEN = () => localStorage.getItem("token");
// 设置token
export const SET_TOKEN = (token: string) => localStorage.setItem("token", token);
// 清除token
export const REMOVE_TOKEN = ()=>{
    // 清除token
    localStorage.removeItem("token");
    // 跳转至登陆界面
    router.push({
        path:"/login",
        query:{
            returnUrl:router.currentRoute.value.path
        }
    })
}